import { ATeamCombat } from "GameLoop/WorldState/EntityManager/Entitys";
import { BinaryDecision } from "framework/FSM/DecisionTree/Decision";
 

/**
 * 是否在准备战斗的范围内
*/
export class DecisionIsCombatMove <T extends IStateArg<ATeamCombat,ITask>> extends BinaryDecision<T>
{

    public testValue(arg:T): boolean
    {
        const goal = arg.entity.moveTarget();
       
        if(!goal)
        {
            //arg.entity.log("info","小队战斗判断",goal,'准备战斗');
            return false;
        }
        if(arg.entity.isToughWillbeBroken())
        {
            return true;
        }
        const path = arg.entity.path;
        const creeps = arg.entity.getAttackableCreeps();
        //arg.entity.log("info",`战斗移动判断:周围敌方单位${_.map(creeps,e=>e.pos)}`);
        if(creeps.length==0)
        {
            // 周围的敌方单位没有时，贴贴了在变为战斗状态
            if(arg.entity.isInCombatRange(goal.pos,2))
            {
               // arg.entity.log("info",`周围没有敌方单位切换到离目的地只有1`,"切换战斗状态");
                return true;
            }
        }
        if(path)
        {
            return arg.entity.isInCombatRange(goal.pos,6) &&path.path.length-path.index<6
        }
        return arg.entity.isInCombatRange(goal.pos,6);
        
        // return true;
    }

    value: any;


    public setValue(val: any)
    {
        this.value = val;
        return this;
    }
}

